#include "Lianghao.h"
#include "ActiveConnsList.h"


void LiangHao::getJoinBidNumPlayers(int nUserID, int bid, int nPrice, int nWeiguanCnt, int bidCnt, int sec)
{
	FrontClientHandler *pHandle = ActiveConnsList::instance()->find(nUserID);
	if(!pHandle)
		return;

	SQLReq *req = SQLMemoryPool::instance()->mallocReq();
	snprintf( req->sql, sizeof(req->sql), "SELECT distinct(user_id) FROM lianghao_user WHERE lh_id = %d", bid);
	req->req_type = REQ_TYPE_LIANG_HAO;
	req->id = nUserID;
	req->client = pHandle;
	DataBaseReadThreadPool::instance()->pushQueue(req);

	TLiangHaoInfo stu;
	stu.nBidID = bid; stu.nPrice = nPrice; stu.nBidCnt = bidCnt; stu.nSec = sec; stu.nWeiguanCnt = nWeiguanCnt;
	m_Lianghao[nUserID] = stu;
	
}

void LiangHao::OnDBMsg(SQLResp * resp,FrontClientHandler *handle)
{
	if(resp->result == 0 || handle == NULL)
		return;
	Player *pUser = handle->getPlayer();
	if(pUser == NULL)
		return;
	MLiangHaoInfo::iterator iter = m_Lianghao.find(pUser->get_user_id());
	if(iter == m_Lianghao.end())
		return;

	TLiangHaoInfo &stu = iter->second;
	
	DB_GET_BID_USER *pMsg = (DB_GET_BID_USER*)resp->data;
	for(int idx = 0;idx < pMsg->count; idx++)
	{
		int nUserID = pMsg->szContent[idx];
		FrontClientHandler *pSendHandler = ActiveConnsList::instance()->find(nUserID);
		if(!pSendHandler)
			continue;
		StreamPacketBuilder::instance()->notifyLianghao(pSendHandler, stu);
	}

	m_Lianghao.erase(iter->first);
}